Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Threading.​Tasks.​TaskCompletionSource<​TResult>

Assembly: System.Runtime

Inheritance: object → TaskCompletionSource

Represents the producer side of a <see cref="T:System.Threading.Tasks.Task`1" /> unbound to a delegate, providing access to the consumer side through the <see cref="P:System.Threading.Tasks.TaskCompletionSource`1.Task" /> property.

Properties

public Task<​TResult>
Task
Gets the <see cref="T:System.Threading.Tasks.Task`1" /> created by this <see cref="T:System.Threading.Tasks.TaskCompletionSource`1" /> .

Methods

public void
SetCanceled​()
Transitions the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Canceled" /> state.
public void
SetCanceled​(CancellationToken cancellationToken)
Transitions the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Canceled" /> state using the specified token.
cancellationToken The cancellation token with which to cancel the <see cref="T:System.Threading.Tasks.Task`1" /> .
public void
SetException​(Collections.​Generic.​IEnumerable<​Exception> exceptions)
Transitions the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Faulted" /> state and binds a collection of exception objects to it.
exceptions The collection of exceptions to bind to this <see cref="T:System.Threading.Tasks.Task`1" /> .
public void
SetException​(Exception exception)
Transitions the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Faulted" /> state and binds it to a specified exception.
exception The exception to bind to this <see cref="T:System.Threading.Tasks.Task`1" /> .
public void
SetFromTask​(Task<​TResult> completedTask)
Transitions the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the same completion state as the specified <paramref name="completedTask" /> .
completedTask The completed task whose completion status (including result, exception, or cancellation information) should be copied to the underlying task.
public void
SetResult​(TResult result)
Transitions the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.RanToCompletion" /> state.
result The result value to bind to this <see cref="T:System.Threading.Tasks.Task`1" /> .
public bool
TrySetCanceled​()
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Canceled" /> state.
Returns <see langword="true" /> if the operation was successful; false if the operation was unsuccessful or the object has already been disposed.
public bool
TrySetCanceled​(CancellationToken cancellationToken)
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Canceled" /> state and enables a cancellation token to be stored in the canceled task.
Returns <see langword="true" /> if the operation is successful; otherwise, <see langword="false" /> .
cancellationToken A cancellation token.
public bool
TrySetException​(Collections.​Generic.​IEnumerable<​Exception> exceptions)
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Faulted" /> state and binds a collection of exception objects to it.
Returns <see langword="true" /> if the operation was successful; otherwise, <see langword="false" /> .
exceptions The collection of exceptions to bind to this <see cref="T:System.Threading.Tasks.Task`1" /> .
public bool
TrySetException​(Exception exception)
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.Faulted" /> state and binds it to a specified exception.
Returns <see langword="true" /> if the operation was successful; otherwise, <see langword="false" /> .
exception The exception to bind to this <see cref="T:System.Threading.Tasks.Task`1" /> .
public bool
TrySetFromTask​(Task<​TResult> completedTask)
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the same completion state as the specified <paramref name="completedTask" /> .
Returns <see langword="true" /> if the operation was successful; otherwise, <see langword="false" /> .
completedTask The completed task whose completion status (including result, exception, or cancellation information) should be copied to the underlying task.
public bool
TrySetResult​(TResult result)
Attempts to transition the underlying <see cref="T:System.Threading.Tasks.Task`1" /> into the <see cref="F:System.Threading.Tasks.TaskStatus.RanToCompletion" /> state.
Returns <see langword="true" /> if the operation was successful; otherwise, <see langword="false" /> .
result The result value to bind to this <see cref="T:System.Threading.Tasks.Task`1" /> .
public bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj The object to compare with the current object.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns a string that represents the current object.
Returns A string that represents the current object.